<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .father {
      width: 300px;
      height: 300px;
      background-color: red;
    }

    .son {
      width: 300px;
      height: 50px;
      background-color: green;
    }
  </style>
</head>

<body>
  <div class="father">
    <div class="son">儿子</div>
  </div>
  <button class="btn1">添加新元素</button>
  <button class="btn2">删除儿子</button>
  <script>
    //  创建 4个 DOM对象
    const father = document.querySelector('.father')
    const son = document.querySelector('.son')
    const btn1 = document.querySelector('.btn1')
    const btn2 = document.querySelector('.btn2')

    // 添加新元素
    btn1.addEventListener('click', function () {
      // 创建 DOM对象节点 input输入框
      // const input = document.createElement('input')

      // 创建 DOM对象节点 img为图片
      const img = document.createElement('img')
      img.src = 'https://llsix.com/content/uploadfile/202401/ee501704512650.png'
      img.width = 300

      // 添加到开头
      // father.prepend(input)
      // 添加到结尾节点
      father.append(img)
    })

    // 删除儿子
    btn2.addEventListener('click', function () {
      // 删除儿子
      son.remove()
    })
  </script>
</body>

</html>